//

//
//  值的操作

#import "StringUtil.h"

@implementation StringUtil

//判断字符串是否为空
+ (BOOL )  isEmpty:(NSString *) s
{
    
    if (s == nil || [[NSNull null] isEqual:s]) {
        return YES;
    } else if ([s length] == 0) {
        return YES;
    } else {
        s = [s stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
        if ([s length] == 0) {
            return YES;
        }
    }
    
    return NO;
}

+(NSString *) notEmpty:(id) s {
    return (s == nil || s == NULL) ? @"" : [NSString stringWithFormat:@"%@", s];
}

//获取NSDictionary对应的值，如果为nil则转换为空字符串
+(NSString *) strForDicKey:(NSDictionary *)dic andKey:(NSString *)key {
    if (dic && key && ![key isEqualToString:@""])
    {
        return [self notEmpty:[dic objectForKey:key]];
    }
    else
    {
        return @"";
    }
}



//NSString中去除html标签
+ (NSString *) stringByStrippingHTML:(NSString *)s
{
    NSRange r;
    while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
        s = [s stringByReplacingCharactersInRange:r withString:@""];
    return s;
}



+ (BOOL) containsWith :(NSString *) s1  instr: (NSString *) s2;
{
    
    if (s1==nil || s2==nil)
        return false;
    NSRange range=[s1 rangeOfString:s2];
    if(range.location!=NSNotFound){
        return true;
    }else{
        return false;
    }
}

+(NSString*) jsonKeyStringWithJson :(NSDictionary * ) json  key :(NSString *)key;
{
    
    NSString *result = [NSString stringWithFormat:@"%@", [json objectForKey:key]];
    return result;
    
}



+(NSString*) trim :(NSString * ) str
{
    if(str==nil)
        return @"";
    return  [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    
}



@end
